<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class AController extends CController
{
	public $layout='//layouts/cloumn-wwpblogadmin-1';

	public $adminpublic=array();

	public $breadcrumbs=array();
        
        private $_metaDescription;
        
        private $_metaKeywords;
        
        private $_pageTitle;
        
        public $openGraph = array();
        
        public $noIndex = false;

        public function init()
	{
		parent::init();
		
		$this->checklogin();
		
		$this->adminpublic['adminData'] = $this->getAdminSession();
		
		$asearchfrom = new AsearchForm();
        $search = $this->renderPartial('/leftside/left_side_search',array(
            'asearchfrom'=>$asearchfrom
        ),true);            
        $leftsidecontent = $this->renderPartial('/leftside/left_side',array(
        	'adminData'=>$this->adminpublic['adminData'],
            'search'=>$search
        ),true);
        
        $rightsidetop = $this->renderPartial('/rightsidetop/right_side_top',array(
            'adminData'=>$this->adminpublic['adminData']
        ),true);
        
        $this->adminpublic['leftsidecontent'] = $leftsidecontent;
        $this->adminpublic['rightsidetop'] = $rightsidetop;
	}
	
	public function getAdminSession()
	{
		$adminData = array();
		$adminData['admin_username'] = Yii::app()->user->getName();
		$adminData['admin_id'] = Yii::app()->user->getId();
		$adminData['admin_shell'] = Yii::app()->user->getState('admin_shell');
		return $adminData;
	}
	
	public function checklogin()
	{
		if(Yii::app()->user->getIsGuest())
		 	Yii::app()->user->loginRequired();
	}
        
        public function getMetaDescription()
        {
            if($this->_metaDescription !== null)
                return $this->_metaDescription;
            else
            {
                $name=ucfirst(basename($this->getId()));
		if($this->getAction()!==null && strcasecmp($this->getAction()->getId(),$this->defaultAction))
			return $this->_metaDescription = Yii::app()->name.' - '.ucfirst($this->getAction()->getId()).' '.$name.' | '.Yii::app()->params['metaDKT'];
		else
			return $this->_metaDescription = Yii::app()->name.' - '.$name.' | '.Yii::app()->params['metaDKT'];
            }
        }
        
        public function setMetaDescription($value="")
        {
             $name=ucfirst(basename($this->getId()));
	     if($this->getAction()!==null && strcasecmp($this->getAction()->getId(),$this->defaultAction))
		$this->_metaDescription = $value.' | '.Yii::app()->name.' - '.ucfirst($this->getAction()->getId()).' '.$name.' | '.Yii::app()->params['metaDKT'];
	     else
		$this->_metaDescription = $value.' | '.Yii::app()->name.' - '.$name.' | '.Yii::app()->params['metaDKT'];
        }
        
        public function getMetaKeywords()
        {
           if($this->_metaKeywords !== null)
                return $this->_metaKeywords;
            else
            {
                $name=ucfirst(basename($this->getId()));
		if($this->getAction()!==null && strcasecmp($this->getAction()->getId(),$this->defaultAction))
			return $this->_metaKeywords=Yii::app()->name.' - '.ucfirst($this->getAction()->getId()).' '.$name.' | '.Yii::app()->params['metaDKT'];
		else
			return $this->_metaKeywords=Yii::app()->name.' - '.$name.' | '.Yii::app()->params['metaDKT'];
            }
        }
        
        public function setMetaKeywords($value = "")
        {
             $name=ucfirst(basename($this->getId()));
	     if($this->getAction()!==null && strcasecmp($this->getAction()->getId(),$this->defaultAction))
		$this->_metaKeywords = $value.' | '.Yii::app()->name.' - '.ucfirst($this->getAction()->getId()).' '.$name.' | '.Yii::app()->params['metaDKT'];
	     else
		$this->_metaKeywords = $value.' | '.Yii::app()->name.' - '.$name.' | '.Yii::app()->params['metaDKT'];
        }
        
        public function setPageTitle($value)
	{
             $name=ucfirst(basename($this->getId()));
	     if($this->getAction()!==null && strcasecmp($this->getAction()->getId(),$this->defaultAction))
		$this->_pageTitle = $value.' | '.Yii::app()->name.' - '.ucfirst($this->getAction()->getId()).' '.$name.' | '.Yii::app()->params['metaDKT'];
	     else
		$this->_pageTitle = $value.' | '.Yii::app()->name.' - '.$name.' | '.Yii::app()->params['metaDKT'];
	}
        
        public function getPageTitle()
	{
		if($this->_pageTitle!==null)
			return $this->_pageTitle;
		else
		{
			$name=ucfirst(basename($this->getId()));
			if($this->getAction()!==null && strcasecmp($this->getAction()->getId(),$this->defaultAction))
				return $this->_pageTitle=Yii::app()->name.' - '.ucfirst($this->getAction()->getId()).' '.$name.' | '.Yii::app()->params['metaDKT'];
			else
				return $this->_pageTitle=Yii::app()->name.' - '.$name.' | '.Yii::app()->params['metaDKT'];
		}
	}
}